<?PHP
 
class Admin_wrapper_Controller extends controller_admin{
	function __construct(){
		parent::__construct();
	 	$this->assign('nav','首页轮播图维护');
		$this->assign('menuid1','1');
		$this->assign('menuid2','6');
		
		//权限判断
		factory::module('admin')->authSys('wrapper'); 
	}
	 
	function index__(){
		if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
		{
			$_POST=format::addslash_deep($_POST);
	 
			$db = factory::getDBO();
			$db->begin();
			//主表  
	 //$db->loadresult('select max(show_index)+1 from t_wrapper ') 
			$wrapper_id = $db->insert('wrapper',array(
				'pic'=>'',
				'show_index'=> 0
			));
			if(!$wrapper_id){
				url::msgalert('操作失败！');
			}
 
			# 首页图片显示文件分析
			if($_FILES['pic']['name']){
				$UploadFiles = uploadfile::singleton();
				# 做一些大小类型设置 
				$UploadFiles->set_base_directory(factory::getcfg('wrapper_path'));
				$UploadFiles->set_size(factory::getcfg('wrapper_maxsize'));
				$UploadFiles->set_extention(factory::getcfg('wrapper_type')); 
				$UploadFiles->set_file_type($_FILES['pic']['type']);
				$UploadFiles->set_file_name(rand(100000,999999).'.'.preg_replace('/.*\.(.*[^\.].*)*/iU','\\1',$_FILES['pic']['name']));
				$UploadFiles->set_file_size($_FILES['pic']['size']);
				$UploadFiles->set_upfile($_FILES['pic']['tmp_name']);
				$UploadFiles->set_datetime('_'.rand(1,100).'_');
				$UploadFiles->save();
				 
				$db->update('wrapper',array(
					'id'=>$wrapper_id,
					'pic'=>$UploadFiles->get_file_path()
				));
			}else{
				url::msgalert('操作失败！');
			}
			$db->commit();
			url::msgalert('添加成功！',url::build('admin_wrapper','index')); 
		}		
		$db=factory::getDBO();
		$this->assign('rs',$db->loadassoclist('select * from `t_wrapper` order by show_index asc'));
		
	}
 
	/* 删除 */
	function deltype__(){
		$_POST=format::addslash_deep($_POST);
		$db = factory::getDBO();
		$id = $_POST['id'];
		if($db->query('delete from `t_wrapper` where id="'.$id.'" ')){
			exit('{success:1,msg11:"删除成功！"}');
		}else{
			exit('系统繁忙，请稍后重试！');
		} 
	}	
	/* 保存修改 */
	function mdifytype__(){
		$objs = format::addslash_json(json_decode( stripslashes($_POST['objs']) ));
		$db = factory::getDBO();
		if($db->updatelist('wrapper',$objs)){
			exit('{success:1,msg:"保存成功！"}');
		}else{
			exit('系统繁忙，请稍后重试！');
		}
	}	
 
	
    
}
?>